package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author lsyandwh
 * @since 2022-12-02
 */
@Api(tags = "借款人申请")
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    @ApiOperation("查询借款人状态")
    @GetMapping("/getBorrowerStatus")
    public Result getBorrowerStatus(HttpServletRequest request){

        String userId = request.getHeader("userId");

        Integer borrowerStatus = borrowerService.getBorrowerStatus(userId);

        return Result.ok().data("borrowerStatus",borrowerStatus);
    }

    @ApiOperation("借款人信息认证")
    @PostMapping("/save")
    public Result saveBorrower(@RequestBody BorrowerVO borrowerVO,HttpServletRequest request){
        System.out.println("borrowerVO = " + borrowerVO);
        String userId = request.getHeader("userId");

        borrowerService.saveBorrower(borrowerVO,userId);

        return Result.ok().message("提交成功");
    }

}

